home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / PDraw3.0.adf / pdraw_rex.lzh / PlotPolar.pdrx < prev    next >
Text File  |  1992-06-15  |  2KB  |  91 lines

  1. /*
  2. @N
  3.  
  4. This Genie will plot a polar mathematical function in terms of angle 'a'
  5. */
  6. signal on error
  7. signal on syntax
  8.  
  9. msg = PDSetup.rexx(2,0)
  10. units = getclip(pds_units)
  11. if msg ~= 1 then exit_msg(msg)
  12.  
  13. /* numeric digits 8 */
  14. cr    = '0a'x
  15. pi2 = 6.282
  16.  
  17. call pdm_abortplot()
  18. call pdm_initplot(4.25,5.5, 1, -1, 0,"polar")
  19. call pdm_setlinecolor(,"black")
  20. call pdm_plotline("0 5,0 -5,0 0,-4 0,4 0")
  21. call pdm_endplot()
  22. call pdm_updatescreen(1)
  23. call pdm_setlinecolor(,"red")
  24.  
  25. function = getclip(pduser_pfunction)
  26. start = getclip(pduser_pstart)
  27. end = getclip(pduser_pstop)
  28. npoints = getclip(pduser_pnpoints)
  29.  
  30. if units = 3 then
  31. do
  32.     start = pdm_ConvertUnits(1, units, start)
  33.     end = pdm_ConvertUnits(1, units, end)
  34. end
  35.  
  36. form    = "a0:"start || cr"an:360"cr"numpoints:"npoints || cr"function:"function
  37.  
  38. form    = pdm_getform("Enter function of angle 'a'", 30, form)
  39. if form = "" then do
  40.    call pdm_deleteobj("polar")
  41.    exit_msg()
  42. end
  43. parse var form start '0a'x end '0a'x numpoints '0a'x function
  44.  
  45. if ~(datatype(start, n) & datatype(end, n) & datatype(numpoints, n)) then
  46.     exit_msg("Invalid Entry")
  47.  
  48. if units = 3 then
  49. do
  50.     start = pdm_ConvertUnits(units, 1, start)
  51.     end = pdm_ConvertUnits(units, 1, end)
  52. end
  53.  
  54. call setclip(pduser_pfunction, function)
  55. call setclip(pduser_pstart, start)
  56. call setclip(pduser_pstop, end)
  57. call setclip(pduser_pnpoints, npoints)
  58.  
  59. start = start / 360 * pi2
  60. end = end / 360 * pi2
  61. inc    = (end - start) / numpoints
  62.  
  63. do a = start to end by inc
  64.     interpret "r = "function
  65.     x = r * cos(a)
  66.     y = r * sin(a)
  67.     if y < -6 then y = -6
  68.     if y > 6 then y = 6
  69.     if x < -6 then x = -6
  70.     if x > 6 then x = 6
  71.     call pdm_plotsmooth(x" "y)
  72.  
  73. end
  74. call pdm_endplot()
  75.  
  76. exit_msg()
  77.  
  78. exit_msg: procedure expose units
  79. do
  80.     parse arg message
  81.  
  82.     if message ~= '' then call pdm_Inform(1,message,)
  83.     call pdm_SetUnits(units)
  84.     call pdm_AutoUpdate(1)
  85.     exit
  86. end
  87.  
  88. error:
  89. syntax:
  90.     exit_msg("Function failed due to error: "errortext(rc))
  91.